package gui.newgui.informationpanel;

import gui.newgui.IController;

import java.util.Observable;
import java.util.Observer;

import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;

import tournamentData.TournamentData;
import db.newversion.ArchersDB;
import db.newversion.DbEntry;
import db.newversion.DistancesDB;

public class InformationPanelController implements IController, Observer {
	InformationPanel window;

	public InformationPanelController(InformationPanel informationPanel) {
		this.window = informationPanel;
		ArchersDB.getInstance().addObserver(this);
		TournamentData.getInstance().addObserver(this);
	}

	@Override
	public void updateTable() {
		// TODO Auto-generated method stub
	}

	@Override
	public void update(Observable arg0, Object arg1) {
		this.updateTextBoxes();

	}

	public void setDropDown() {
		ComboBoxModel model = new DefaultComboBoxModel(DistancesDB.getInstance().getAll(DbEntry.TOURNAMENT_TYPE));
		this.window.getTournamentTypeDropDown().setModel(model);
	}

	private void updateTextBoxes() {
		this.window.getTournamentTypeDropDown().setSelectedItem(TournamentData.getInstance().getGeneralTournamentInformation().getTournamentType());
		this.window.getTournamentNameTextField().setText(TournamentData.getInstance().getGeneralTournamentInformation().getTournamentName());
		this.window.getStartDateTextField().setText(TournamentData.getInstance().getGeneralTournamentInformation().getStartDate().toString());
		this.window.getEndDateTextField().setText(TournamentData.getInstance().getGeneralTournamentInformation().getEndDate().toString());
		this.window.getOrganizerTextField().setText(TournamentData.getInstance().getGeneralTournamentInformation().getOrganizer());
		this.window.getTournamentLeadTextField().setText(TournamentData.getInstance().getGeneralTournamentInformation().getTournamentLead());
		this.window.getRefereeTextField().setText(TournamentData.getInstance().getGeneralTournamentInformation().getReferee());
	}

}
